class ParticipantsController < ApplicationController

  before_filter :participant_authorize

  def index
    @workshop = Workshop.find(params[:workshop_id])
  end

  def new
    @participant = User.new(:workshop_id => params[:workshop_id])
  end

  def create
    @participant = User.new(params[:participant])

    if @participant.save
      redirect_to(:action => 'index', :workshop_id => @participant.workshop_id)
    else
      render :action => 'new'
    end
  end

  def destroy
    User.destroy(params[:id])
    redirect_to(:action => 'index', :workshop_id => params[:workshop_id])
  end

  private

  def participant_authorize
    head :forbidden if !current_user.is_administrator
  end

end
